package com.trc.edu.web.controller;

import com.trc.edu.model.User;
import com.trc.edu.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private IUserService userService;



    @RequestMapping("userLogin")
    public String userLogin(User loginUser, HttpSession session){
        //System.out.println(loginUser.getUsername());
        String loginUserPassword = loginUser.getPassword();
        String loginUserName = loginUser.getUsername();

        User user = userService.login(loginUserName,loginUserPassword);
        if (user!=null){
            session.setAttribute("loginUser",user);
            return "index";
        }
        System.out.println("登陆失败");
        return "login";
    }
}
